package com.smart.utils;

import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;

/**
 * @author lgb
 * @date 2020年6月13日 下午5:32:16 Copyright (C) 深圳工勘科技
 * @说明: 分页参数
 **/
public class Pageable implements Serializable {

	private static final long serialVersionUID = -1486923283258390657L;
	/** 默认页码 */
	private static final int DEFAULT_PAGE_NUMBER = 1;
	/** 默认每页记录数 */
	private static final int DEFAULT_PAGE_SIZE = 10;
	/** 最大每页记录数 */
	private static final int MAX_PAGE_SIZE = 30;
	/** 搜索列表 */
	private Map<String,String> search = new HashMap<String,String>();
	/** 页码 */
	private int pageNum = DEFAULT_PAGE_NUMBER;
	/** 每页记录数 */
	private int pageSize = DEFAULT_PAGE_SIZE;

	public Pageable() {}

	/**
	 * 初始化一个新创建的Pageable对象
	 * @param page 页码
	 * @param limit 每页记录数
	 **/
	public Pageable(Integer pageNum, Integer pageSize) {
		this.pageNum = pageNum;
		this.pageSize = pageSize;
	}

	public Map<String, String> getSearch() {
		return search;
	}
	public void setSearch(Map<String, String> search) {
		this.search = search;
	}
	/**
	 * 获取页码
	 * @return 页码
	 **/
	public int getPageNum() {
		return pageNum;
	}
	/**
	 * 设置页码
	 * @param pageNumber 页码
	 **/
	public void setPageNum(int pageNum) {
		if (pageNum < 1) {
			pageNum = DEFAULT_PAGE_NUMBER;
		}
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		if (pageSize > MAX_PAGE_SIZE) {
			pageSize = MAX_PAGE_SIZE;
		}
		if (pageSize < DEFAULT_PAGE_NUMBER) {
			pageSize = DEFAULT_PAGE_NUMBER;
		}
		this.pageSize = pageSize;
	}
}